package com.example.Sao.MyFragment;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.Sao.R;
import com.example.Sao.Tools.ObjectBoxHelper;
import com.wang.avi.AVLoadingIndicatorView;

/**
 * @ProjectName: scan
 * @Package: com.example.Sao.MyFragment
 * @ClassName: WaitDialog
 * @Description: java类作用描述
 * @Author: 作者名
 * @CreateDate: 2020/5/31 20:30
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/5/31 20:30
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class WaitDialog extends DialogFragment implements View.OnClickListener{
    private String title;
    private TextView mess;
    private Context mContext;
    private AVLoadingIndicatorView indicatorView;
    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }
    public void setTitle(String title){
        this.title = title;
    }
    @Override
    public void onViewCreated(View view,Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        indicatorView = view.findViewById(R.id.IndicatorView);
        mess = view.findViewById(R.id.title_text);
    }

    @Override
    public void onStart() {
        super.onStart();
        mess.setText(title);
        indicatorView.show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        indicatorView.hide();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Window window = this.getDialog().getWindow();
        //去掉dialog默认的padding
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.75);
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //设置dialog的位置在底部
        lp.gravity = Gravity.CENTER;
        //设置dialog的动画
        lp.windowAnimations = R.style.dialogAnim;
        window.setAttributes(lp);
        window.setBackgroundDrawable(new ColorDrawable());
        getDialog().setCanceledOnTouchOutside(false);//点击屏蔽不消失
        View view = inflater.inflate(R.layout.fragment_wait_layout,container,false);
        return view;
    }

    @Override
    public void onClick(View v) {

    }
}
